<template>
  <view class="category_wrap">
    <navigator :url="`/pages/imgCategory/index?id=${item.id}`" class="cate_item" v-for="item in categoryList" :key="item.id">
      <view class="cate_img">
        <image mode="aspectFill" :src="item.cover"></image>
      </view>
      <view class="name">
        {{ item.name }}
      </view>
    </navigator>
  </view>
</template>

<script>
export default {
  mounted() {
    // 修改页面的标题
    uni.setNavigationBarTitle({ title: "分类" });
    this.getList();
  },
  data() {
    return {
      //分类列表
      categoryList: [],
    };
  },
  methods: {
    //获取分类数据
    getList() {
      this.request({
        url: "http://157.122.54.189:9088/image/v1/vertical/category",
      }).then((res) => {
        console.log(res);
        this.categoryList = res.res.category;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.category_wrap {
  display: flex;
  flex-wrap: wrap;
  padding: 2rpx;
  .cate_item {
    width: 33.33%;
    position: relative;
    border: 2px solid #fff;
    .cate_img {
      image {
        height: 240rpx;
      }
    }

    .name {
      position: absolute;
      bottom: 0;
      left: 10rpx;
      color: #fff;
      font-weight: 500;
      width: 100%;
      height: 40rpx;
      //c3渐变
      background-image: linear-gradient(
        to right top,
        rgba(0, 0, 0, 0.2),
        rgba(0, 0, 0, 0)
      );
    }
  }
}
</style>
